<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>async/await之优化promise请求</title>
    <!-- 导入vue库依赖 -->
    <script src="./js/vue.js"></script>

    <!-- 第三方网络请求依赖库  -->
    <script src="./js/axios.js"></script>
    <script src="./js/vue-router.js"></script>
</head>

<body>
    <div id="app"></div>
    <script>
        // 在函数上添加修饰符 async  在axios请求上添加await 可以将异步请求转化成同步请求的方式


        async function queryData() {
            var ret = await axios.get(url);
            console.log(ret.data);
            return ret.data;
        }

        queryData.then(function(ret) {
            console.log(ret);
        })


        // async处理多个异步请求的过程

        async function queryData() {
            var info = await axios.get(url);
            var ret = await axios.get("data2?info=" + info.data)
            return ret;
        }

        queryData.then(function(data) {
            console.log(data);
        })

        var vm = new Vue({
            el: '#app',
            data: {
                msg: ''
            },
            methods: {},
        })
    </script>
</body>

</html>